package com.ler.yrmall.webapp.service;

import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.ler.yrmall.webapp.config.YuruoAuthProperties;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author Leron
 * @version 1.0
 */
@Service
public class YuruoAuthService {

    @Resource
    private YuruoAuthProperties yuruoAuthProperties;

    public Map<String,String> getToken(String code) {
        String url = String.format(yuruoAuthProperties.getTokenUrl(), yuruoAuthProperties.getClientId(), yuruoAuthProperties.getClientSecret(),code ,yuruoAuthProperties.getRedirectUri());
        String body = HttpRequest.post(url).execute().body();
        return JSON.parseObject(body,new TypeReference<Map<String,String>>(){});
    }

}
